/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package planspiel;

import admintool.imp03_data.IMP03_Candidate;
import admintool.imp03_data.IMP03_Message;
import admintool.imp03_data.IMP03_Platform;
import admintool.imp03_data.IMP03_Tip;
import admintool.imp03_data.IMP03_Vacancy;
import java.util.ArrayList;

/**
 *
 * @author Administrator
 */
/**
 * @author wolfgang
 *
 */
public class GameRoundController {

    //Constants
    /**
     * 
     */
    public static int VACANCYSTAGE = 1;
    /**
     * 
     */
    public static int PLATFORMSTAGE = 2;
    /**
     * 
     */
    public static int CANDIDATESTAGE = 3;
    /**
     * 
     */
    public static int MESSAGESTAGE = 4;
    /**
     * 
     */
    public static int TIPSTAGE = 5;
    /**
     * 
     */
    public static int FINISHED = 6;
    
    //Round
    private int roundID = -1;
    
    //Buttons
    private boolean vacancyButtonEnabled = false;
    private boolean platformButtonEnabled = false;
    private boolean candidatesButtonEnabled = false;
    private boolean messagesButtonEnabled = false;
    private boolean tipsButtonEnabled = false;

    //Current stage
    // 1 = Vacancy
    // 2 = Platform
    // 3 = Candidates
    // 4 = Messages
    // 5 = Tips
    // 6 = Finished
    private int selectedGameStage = -1;

    //Selected Game-Objects
    private IMP03_Vacancy selectedVacancy = null;
    private IMP03_Platform selectedPlatform = null;
    private IMP03_Candidate selectedCandidate = null;
    private IMP03_Message selectedMessage = null;
    
    //Timer
    CountdownTimer countdownTimer = null;
    BudgetTimer budgetTimer = null;
    
    //Costs
    int headhuntingCosts = -1;
    
    //Tips
    private ArrayList<IMP03_Tip> alreadyPresentedTips = new ArrayList<IMP03_Tip>();

    /**
     * 
     * @param vacancyButtonEnabled
     * @param platformButtonEnabled
     * @param candidatesButtonEnabled
     * @param messagesButtonEnabled
     * @param tipsButtonEnabled
     * @param selectedGameStage
     * @param selectedVacancy
     * @param selectedPlatform
     * @param selectedCandidate
     * @param roundID
     * @param headhuntingCosts
     */
    public GameRoundController(boolean vacancyButtonEnabled, boolean platformButtonEnabled, 
            boolean candidatesButtonEnabled, boolean messagesButtonEnabled, boolean tipsButtonEnabled,
            int selectedGameStage, IMP03_Vacancy selectedVacancy, IMP03_Platform selectedPlatform, IMP03_Candidate selectedCandidate, int roundID,
            int headhuntingCosts) {
        this.vacancyButtonEnabled = vacancyButtonEnabled;
        this.platformButtonEnabled = platformButtonEnabled;
        this.candidatesButtonEnabled = candidatesButtonEnabled;
        this.messagesButtonEnabled = messagesButtonEnabled;
        this.tipsButtonEnabled = tipsButtonEnabled;
        this.selectedGameStage = selectedGameStage;
        this.selectedVacancy = selectedVacancy;
        this.selectedPlatform = selectedPlatform;
        this.selectedCandidate = selectedCandidate;
        this.roundID = roundID;
        
        //init the global timer
        countdownTimer = new CountdownTimer();
        countdownTimer.startTimer();
    }

    /**
     * 
     * @return
     */
    public boolean isCandidatesButtonEnabled() {
        return candidatesButtonEnabled;
    }

    /**
     * 
     * @return
     */
    public boolean isMessagesButtonEnabled() {
        return messagesButtonEnabled;
    }

    /**
     * 
     * @return
     */
    public boolean isPlatformButtonEnabled() {
        return platformButtonEnabled;
    }

    /**
     * 
     * @return
     */
    public int getSelectedGameStage() {
        return selectedGameStage;
    }

    /**
     * 
     * @return
     */
    public IMP03_Platform getSelectedPlatform() {
        return selectedPlatform;
    }

    /**
     * 
     * @return
     */
    public IMP03_Vacancy getSelectedVacancy() {
        return selectedVacancy;
    }

    /**
     * 
     * @return
     */
    public boolean isTipsButtonEnabled() {
        return tipsButtonEnabled;
    }

    /**
     * 
     * @return
     */
    public boolean isVacancyButtonEnabled() {
        return vacancyButtonEnabled;
    }

    /**
     * 
     * @param candidatesButtonEnabled
     */
    public void setCandidatesButtonEnabled(boolean candidatesButtonEnabled) {
        this.candidatesButtonEnabled = candidatesButtonEnabled;
    }

    /**
     * 
     * @param messagesButtonEnabled
     */
    public void setMessagesButtonEnabled(boolean messagesButtonEnabled) {
        this.messagesButtonEnabled = messagesButtonEnabled;
    }

    /**
     * 
     * @param platformButtonEnabled
     */
    public void setPlatformButtonEnabled(boolean platformButtonEnabled) {
        this.platformButtonEnabled = platformButtonEnabled;
    }

    /**
     * 
     * @param selectedGameStage
     */
    public void setSelectedGameStage(int selectedGameStage) {
        this.selectedGameStage = selectedGameStage;
    }

    /**
     * 
     * @param selectedPlatform
     */
    public void setSelectedPlatform(IMP03_Platform selectedPlatform) {
        this.selectedPlatform = selectedPlatform;
    }

    /**
     * 
     * @param selectedVacancy
     */
    public void setSelectedVacancy(IMP03_Vacancy selectedVacancy) {
        this.selectedVacancy = selectedVacancy;
    }

    /**
     * 
     * @param tipsButtonEnabled
     */
    public void setTipsButtonEnabled(boolean tipsButtonEnabled) {
        this.tipsButtonEnabled = tipsButtonEnabled;
    }

    /**
     * 
     * @param vacancyButtonEnabled
     */
    public void setVacancyButtonEnabled(boolean vacancyButtonEnabled) {
        this.vacancyButtonEnabled = vacancyButtonEnabled;
    }

    /**
     * 
     * @return
     */
    public int getRoundID() {
        return roundID;
    }

    /**
     * 
     * @return
     */
    public CountdownTimer getCountdownTimer() {
        return countdownTimer;
    }

    /**
     * 
     * @return
     */
    public BudgetTimer getBudgetTimer() {
        return budgetTimer;
    }

    /**
     * 
     * @return
     */
    public IMP03_Candidate getSelectedCandidate() {
        return selectedCandidate;
    }

    /**
     * 
     * @param selectedCandidate
     */
    public void setSelectedCandidate(IMP03_Candidate selectedCandidate) {
        this.selectedCandidate = selectedCandidate;
    }
    
    /**
     * Erzeugt und startet einen neuen Budget-Timer.
     * @param round 
     */
    public void startBudgetTimer(GameRound round) {
    	budgetTimer = new BudgetTimer(round);
     	budgetTimer.startTimer();
    }

    /**
     * @return the selectedMessage
     */
    public IMP03_Message getSelectedMessage() {
            return selectedMessage;
    }

    /**
     * @param selectedMessage the selectedMessage to set
     */
    public void setSelectedMessage(IMP03_Message selectedMessage) {
            this.selectedMessage = selectedMessage;
    }

    
    public IMP03_Tip getTipForCurrentStage(){
        IMP03_Tip retVal = IMP03_Tip.getEmptyTipObject();
        ArrayList<IMP03_Tip> tmpTips = IMP03_Tip.getAllAvailableTipsFromDB(false);
        
        if(getSelectedVacancy() == null){
            for(IMP03_Tip tmpTip : tmpTips){
                if(tmpTip.getStageID() == VACANCYSTAGE){
                    if(!alreadyPresentedTips.contains(tmpTip)){
                        alreadyPresentedTips.add(tmpTip);
                        retVal = tmpTip;
                        break;
                    }
                }
            }
        } else if(getSelectedPlatform() == null){
            for(IMP03_Tip tmpTip : tmpTips){
                if(tmpTip.getStageID() == PLATFORMSTAGE){
                    if(!alreadyPresentedTips.contains(tmpTip)){
                        alreadyPresentedTips.add(tmpTip);
                        retVal = tmpTip;
                        break;
                    }
                }
            }
        } else if(getSelectedCandidate() == null){
            for(IMP03_Tip tmpTip : tmpTips){
                if(tmpTip.getStageID() == CANDIDATESTAGE){
                    if(!alreadyPresentedTips.contains(tmpTip)){
                        alreadyPresentedTips.add(tmpTip);
                        retVal = tmpTip;
                        break;
                    }
                }
            }
        }
        
        return retVal;
    }
    
}
